<template>
    <!-- 课程管理-->
    <div>
        <!--    搜索栏-->
        <el-card id="serch">
            <el-row>
                <el-col :span="18">
                    <div style="margin-top: 15px;">
                        <!-- <el-input placeholder="请输入内容" v-model="searchModel.name" class="input-with-select"> -->
                            <el-select v-model="searchModel.wn" clearable placeholder="请选择类别">
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                            <el-select v-model="searchModel.ks" clearable placeholder="是否参加考试">
                                <el-option v-for="item in kaoshi" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>

                            <el-button slot="append" @click="getStudentList" type="primary"
                                icon="el-icon-search">搜索</el-button>
                        <!-- </el-input> -->
                    </div>
                </el-col>
                <el-col :span="6" align="right">
                    <el-button @click="OpenEditUI(null)" type="primary" icon="el-icon-plus">添加</el-button>
                </el-col>
            </el-row>
        </el-card>
        <!--    结果栏-->
        <el-card>
            <el-table :data="studentList" border stripe style="width: 100%">
                <!-- <el-table-column label="#" width="80">
                    <template slot-scope="scope">
                        {{ (searchModel.pageNo - 1) * searchModel.pageSize + scope.$index + 1 }}
                    </template>

                </el-table-column> -->
                <el-table-column prop="id" label="#" width="50" align="center">
                </el-table-column>
                <el-table-column prop="titleName" label="名称" width="180" align="center">
                </el-table-column>
                <el-table-column prop="category" label="类别" width="180" align="center">
                </el-table-column>
                <el-table-column prop="judgment" label="是否参加考试" width="180" align="center">
                </el-table-column>
                <el-table-column prop="startTime" label="课程开始时间" width="200" align="center">
                    <span slot-scope="scope">{{ scope.row.startTime | formatUTC }}</span>
                </el-table-column>
                <el-table-column prop="endTime" label="课程结束时间" width="200" align="center">
                    <span slot-scope="scope">{{ scope.row.endTime | formatUTC }}</span>
                </el-table-column>
                <!-- <el-table-column prop="judgment" label="课程开始时间" width="180">
                </el-table-column>
                <el-table-column prop="judgment" label="课程结束时间" width="180">
                </el-table-column> -->

                <el-table-column prop="status" label="状态" width="180" align="center">
                </el-table-column>
                <!-- <el-table-column prop="uid" label="状态" width="180">
                </el-table-column> -->
                <!-- <el-table-column prop="telephone" label="电话" width="120">
                </el-table-column>
                <el-table-column prop="telephone" label="邮箱" width="120">
                </el-table-column>
                <el-table-column prop="address" label="住址" width="180">
                </el-table-column>
                <el-table-column prop="status" label="状态" width="80">
                </el-table-column> -->
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <i size="mini" @click="OpenEditUI(scope.row.id)" class="el-icon-edit" style="margin-right: 20px;">
                        </i>
                        <i size="mini" @click="deleteStudent(scope.row)" class="el-icon-delete-solid">
                        </i>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        <div class="block">

            <!--      <span class="demonstration">分页组件</span>-->
            <!-- <el-pagination background layout="prev, pager, next" :total="1000">
            </el-pagination> -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="searchModel.pageNo" :page-sizes="[5, 10, 15, 20]" :page-size="searchModel.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>

            <!-- 用户信息编辑对话框 -->
            <el-dialog @close="clearForm" :title="title" :visible.sync="dialogFormVisible">
                <el-form :model="studentForm">
                    <el-form-item label="名称" :label-width="formLabelWidth">
                        <el-input v-model="studentForm.titleName" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="类别" :label-width="formLabelWidth">
                        <el-select v-model="studentForm.category" clearable placeholder="请选择类别">
                                <el-option v-for="item in options" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                    </el-form-item>
                    <el-form-item label="是否参加考试" :label-width="formLabelWidth">
                        <el-select v-model="studentForm.judgment" clearable placeholder="是否参加考试">
                                <el-option v-for="item in kaoshi" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                    </el-form-item>
                    <el-form-item>
                        <div class="block">
                            <span class="demonstration" style="margin-left: 70px;">开始时间</span>
                            <el-date-picker v-model="studentForm.startTime" type="date" placeholder="选择日期"
                                style="width: 300px; margin-left: 5px;">
                            </el-date-picker>
                        </div>
                    </el-form-item>
                    <!-- <el-form-item label="结束时间" :label-width="formLabelWidth">
                        <el-input v-model="studentForm.endTime" autocomplete="off"></el-input>
                    </el-form-item> -->
                    <el-form-item>
                        <div class="block">
                            <span class="demonstration" style="margin-left: 70px;">结束时间</span>
                            <el-date-picker v-model="studentForm.endTime" type="date" placeholder="选择日期"
                                style="width: 300px; margin-left: 5px;">
                            </el-date-picker>
                        </div>
                    </el-form-item>
                    <el-form-item label="状态" :label-width="formLabelWidth">
                        <el-select v-model="studentForm.status" placeholder="请选择状态">
                            <el-option v-for="item in zhuangtai" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
<!-- 
                    <el-form-item label="状态" :label-width="formLabelWidth">
                        <el-input v-model="studentForm.status" autocomplete="off"></el-input>
                    </el-form-item> -->
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveUser">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

  
<script>
import users from '@/api/users';
import usersApi from '@/api/discipline'

export default {
    data() {
        return {
            formLabelWidth: '130px',
            studentForm: {},
            title: "",
            dialogFormVisible: false,
            total: 0,
            searchModel: {
                pageNo: 1,
                pageSize: 10,
                wn: '',
                ks: '',
                category: '',
                judgment: '',
                
            },
            studentList: [],
            options: [{
                value: '文科',
                label: '文科'
            }, {
                value: '理科',
                label: '理科'
            }],
            kaoshi: [{
                value: '是',
                label: '是'
            }, {
                value: '否',
                label: '否'
            }

            ],
            zhuangtai: [{
                value: '启用',
                label: '启用'
            }, {
                value: '关闭',
                label: '关闭'
            }]
        }
    },
    methods: {
        deleteStudent(student) {
            usersApi.deleteById(student.id).then(response => {
                this.$message({
                    message: response.message
                });
                this.getStudentList();
                // this.getstudentList();
            });

        },
        saveUser() {
            usersApi.addStudent(this.studentForm).then(response => {
                this.$message({
                    message: response.message,
                    type: 'success'
                });
                this.dialogFormVisible = false;
                this.getStudentList();
            })
            // alert(123)
        },
        clearForm() {
            this.studentForm = {};

        },
        // OpenEditUI(){
        OpenEditUI(uid) {
            if (uid == null) {
                this.title = "新增学科";
            } else {
                this.title = "修改学科";
                usersApi.getById(uid).then(response => {
                    this.studentForm = response.data;
                });

            }

            this.dialogFormVisible = true;
        },
        handleEdit(index, row) {
            console.log(index, row);
        },
        handleDelete(index, row) {
            console.log(index, row);
        },
        handleSizeChange(pageSize) {
            this.searchModel.pageSize = pageSize;
            this.getStudentList();
        },
        handleCurrentChange(pageNo) {
            this.searchModel.pageNo = pageNo;
            this.getStudentList();
        },
        getStudentList() {
            usersApi.getAllStudent(this.searchModel).then(response => {
                this.studentList = response.data.records;
                this.total = response.data.total;
            });
        }
    },
    created() {
        this.getStudentList();
    }
}


</script>
<style>
#serch .el-input {
    width: 200px;
    margin-right: 30px;
}

.el-dialog .el-input {
    width: 80%;
}
</style>
  

